BUILD_FOLDER="build"
if [ ! -d $BUILD_FOLDER ]; then
	mkdir build
fi

cd build

script_dir=$(cd $(dirname $0);pwd)
echo "current path: $script_dir"

cmake .. -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release -DWITH_GIF=ON -DWITH_GIF_EXTERNAL=ON -DWITH_GEOS=ON \
         -DWITH_GEOS_EXTERNAL=ON -DWITH_EXPACT=ON -DWITH_EXPACT_EXTERNAL=ON -DWITH_GTest=ON -DWITH_GTest_EXTERNAL=ON \
		 -DWITH_PROJ=ON -DWITH_PROJ_EXTERNAL=ON -DWITH_SQLite3=ON -DWITH_SQLite3_EXTERNAL=ON -DWITH_HDF4=ON -DWITH_HDF4_EXTERNAL=ON \
		 -DWITH_Spatialite=ON -DWITH_Spatialite_EXTERNAL=ON -DWITH_OCI=ON -DWITH_OCI_EXTERNAL=ON -DWITH_Boost=ON -DWITH_Boost_EXTERNAL=ON \
		 -DWITH_UriParser=ON -DWITH_UriParser_EXTERNAL=ON -DWITH_ZLIB=ON -DWITH_ZLIB_EXTERNAL=ON -DWITH_JSONC=ON -DWITH_JSONC_EXTERNAL=ON -DWITH_ICONV=ON -DWITH_ICONV_EXTERNAL=ON \
		 -DWITH_EXPAT=ON -DWITH_EXPAT_EXTERNAL=ON -DWITH_CURL=ON -DWITH_CURL_EXTERNAL=ON \
		 -DWITH_LibLZMA=ON -DWITH_LibLZMA_EXTERNAL=ON -DWITH_LibXml2=ON -DWITH_LibXml2_EXTERNAL=ON \
		 -DWITH_TIFF=ON -DWITH_TIFF_EXTERNAL=ON -DWITH_JPEG=ON -DWITH_JPEG_EXTERNAL=ON -DWITH_GeoTIFF=ON -DWITH_GeoTIFF_EXTERNAL=ON \
		 -DWITH_JBIG=ON -DWITH_JBIG_EXTERNAL=ON -DWITH_KML=ON -DWITH_KML_EXTERNAL=ON -DWITH_OpenCAD=ON -DWITH_OpenCAD_EXTERNAL=ON \
		 -DWITH_OpenSSL=OFF -DWITH_PostgreSQL=OFF -DCMAKE_INSTALL_PREFIX=../installed
cmake --build . --config Release --target install

# echo the python version
U_V1=`python -V 2>&1|awk '{print $2}'|awk -F '.' '{print $1}'`
U_V2=`python -V 2>&1|awk '{print $2}'|awk -F '.' '{print $2}'`
U_V3=`python -V 2>&1|awk '{print $2}'|awk -F '.' '{print $3}'`

GDAL_SO="$script_dir/../installed/lib/libgdal*"
GDAL_THIRD_PARTY_SO="$script_dir/../build/third-party/install/lib/lib*"
GDAL_PYTHON_SO="$script_dir/../installed/lib/python$U_V1.$U_V2/site-packages"

cp $GDAL_SO -r $GDAL_PYTHON_SO
cp $GDAL_THIRD_PARTY_SO -r $GDAL_PYTHON_SO

echo "Finishing GDAL python interface!"


